/**
 * @description 路由出口页面
 * @author 盘古他爹
 */

import * as Router from "koa-router"

import * as fs from "fs"
import * as path from "path"
const router: Router = new Router()
//自动注册路由
const filePath = path.resolve(__dirname, "./")

/**
 * 
 * @param filePath 地址
 */
function routeAuto(filePath: string) {
    fs.readdirSync(filePath).forEach(file => {
        if (file.includes(".ts") || file.includes(".js")) {
            if (file !== "index.ts" && file !== "index.js") {
                let { route } = require(filePath + "/" + file)
                router.use(route.routes())
                router.use(route.allowedMethods())
            }
        } else {
            routeAuto(path.resolve(filePath, file))
        }
    })
}
routeAuto(filePath)
// console.log("router", router);

export default router

